<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>图书管理列表</title>
  </head>
  <body>
    <div id="app">
      <h3>图书管理列表</h3>
      <ul>
        <li v-for="(item,index) in arr" :key=item.id>
          <span>{{item.id}}</span>
          <span>{{item.name}}</span>
          <span>{{item.author}}</span>
          <span><button @click="arr.splice(index,1)">删除（第一种）</button></span>
          <span><button @click="del(item.id)">删除（第二种）</button></span>
        </li>
      </ul>
    </div>
    <script src="/js/vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          arr: [
            { id: 1, name: "红楼梦", author: "曹雪芹" },
            { id: 2, name: "西游记", author: "吴承恩" },
            { id: 3, name: "水浒传", author: "施耐庵" },
            { id: 4, name: "三国演义", author: "罗贯中" },
          ],
        },
        methods:{
          del(id){
            console.log(this.arr.filter(item => item.id !==id));
            this.arr = this.arr.filter(item => item.id !== id);
            
          }
        }
      });
    </script>
  </body>
</html>
